#############################################################################################
#                                                                                           #
#                   Copyright 2010-2013 Ning, Inc.                                          #
#                   Copyright 2014 Groupon, Inc.                                            #
#                   Copyright 2014 The Billing Project, LLC                                 #
#                                                                                           #
#      The Billing Project licenses this file to you under the Apache License, version 2.0  #
#      (the "License"); you may not use this file except in compliance with the             #
#      License.  You may obtain a copy of the License at:                                   #
#                                                                                           #
#          http://www.apache.org/licenses/LICENSE-2.0                                       #
#                                                                                           #
#      Unless required by applicable law or agreed to in writing, software                  #
#      distributed under the License is distributed on an "AS IS" BASIS, WITHOUT            #
#      WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the            #
#      License for the specific language governing permissions and limitations              #
#      under the License.                                                                   #
#                                                                                           #
#############################################################################################


#
#                       DO NOT EDIT!!!
#    File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
#


module Killbill
  module Plugin
    module Api

      java_package 'org.killbill.billing.usage.api'
      class UsageUserApi

        include org.killbill.billing.usage.api.UsageUserApi

        def initialize(real_java_api)
          @real_java_api = real_java_api
        end


        java_signature 'Java::void recordRolledUpUsage(Java::org.killbill.billing.usage.api.SubscriptionUsageRecord, Java::org.killbill.billing.util.callcontext.CallContext)'
        def record_rolled_up_usage(usage, context)

          # conversion for usage [type = org.killbill.billing.usage.api.SubscriptionUsageRecord]
          usage = usage.to_java unless usage.nil?

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = context.to_java unless context.nil?
          @real_java_api.record_rolled_up_usage(usage, context)
        end

        java_signature 'Java::org.killbill.billing.usage.api.RolledUpUsage getUsageForSubscription(Java::java.util.UUID, Java::java.lang.String, Java::org.joda.time.LocalDate, Java::org.joda.time.LocalDate, Java::org.killbill.billing.util.callcontext.TenantContext)'
        def get_usage_for_subscription(subscriptionId, unitType, startDate, endDate, context)

          # conversion for subscriptionId [type = java.util.UUID]
          subscriptionId = java.util.UUID.fromString(subscriptionId.to_s) unless subscriptionId.nil?

          # conversion for unitType [type = java.lang.String]
          unitType = unitType.to_s unless unitType.nil?

          # conversion for startDate [type = org.joda.time.LocalDate]
          if !startDate.nil?
            startDate = Java::org.joda.time.LocalDate.parse(startDate.to_s)
          end

          # conversion for endDate [type = org.joda.time.LocalDate]
          if !endDate.nil?
            endDate = Java::org.joda.time.LocalDate.parse(endDate.to_s)
          end

          # conversion for context [type = org.killbill.billing.util.callcontext.TenantContext]
          context = context.to_java unless context.nil?
          res = @real_java_api.get_usage_for_subscription(subscriptionId, unitType, startDate, endDate, context)
          # conversion for res [type = org.killbill.billing.usage.api.RolledUpUsage]
          res = Killbill::Plugin::Model::RolledUpUsage.new.to_ruby(res) unless res.nil?
          return res
        end

        java_signature 'Java::java.util.List getAllUsageForSubscription(Java::java.util.UUID, Java::java.util.List, Java::org.killbill.billing.util.callcontext.TenantContext)'
        def get_all_usage_for_subscription(subscriptionId, transitionDates, context)

          # conversion for subscriptionId [type = java.util.UUID]
          subscriptionId = java.util.UUID.fromString(subscriptionId.to_s) unless subscriptionId.nil?

          # conversion for transitionDates [type = java.util.List]
          tmp = java.util.ArrayList.new
          (transitionDates || []).each do |m|
            # conversion for m [type = org.joda.time.LocalDate]
            if !m.nil?
              m = Java::org.joda.time.LocalDate.parse(m.to_s)
            end
            tmp.add(m)
          end
          transitionDates = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.TenantContext]
          context = context.to_java unless context.nil?
          res = @real_java_api.get_all_usage_for_subscription(subscriptionId, transitionDates, context)
          # conversion for res [type = java.util.List]
          tmp = []
          (res || []).each do |m|
            # conversion for m [type = org.killbill.billing.usage.api.RolledUpUsage]
            m = Killbill::Plugin::Model::RolledUpUsage.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          res = tmp
          return res
        end
      end
    end
  end
end
